﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BridgeShips{
    public class ShipsIDDate : UDPDateBase {
        
        //private List<string> m_lst = new List<string>();
        private List<string> m_datelst = new List<string>();
        private uint m_shipID;
        private bool m_isFirstID;//判断是否是第一个ID值
        private Vector3 m_shipWorldPosition;//舟船ID在Unity的世界坐标点

        public uint ShipID
        {
            get { return m_shipID; }
        }
        public override void GetDictionaryDate(string date)
        {
            base.GetDictionaryDate(date);
            if (!m_datelst.Contains(date))
            {
                m_datelst.Add(date);
                ShipsDictionary.Instance.SaveIDs(SpitReceivedMsgs.SpitMsgs(date)[0], SpitReceivedMsgs.SpitMsgs(date));
                //开始初始化舟船
                InitShips(SpitReceivedMsgs.SpitMsgs(date));
                Debug.LogError(date);
            }
        }
        void InitShips(List<string > dateList)
        {
            for (int i = 1; i < dateList.Count; i++)
            {
                //判断该ID是奇数还是偶数
                if (int.Parse(dateList[i])%2==0)
                {
                    m_shipID = ShipsDictionary.Instance.HashCode(uint.Parse(dateList[i]) - 1, uint.Parse(dateList[i]));
                    m_isFirstID = false;
                }
                else
                {
                    m_shipID = ShipsDictionary.Instance.HashCode( uint.Parse(dateList[i]), uint.Parse(dateList[i]) + 1);
                    m_isFirstID = true;
                }
              
                //设置舟船每个ID的Unity世界坐标点
                m_shipWorldPosition = new Vector3(1000.0f, 7.0f, Random.value * 50 + 900.0f);
                if (ShipsDictionary.Instance.IsExistID(m_shipID))
                {
                    ShipsDictionary.Instance.ChangeShipDicValues(m_shipID, m_shipWorldPosition, m_isFirstID);
                }
                else
                {
                    ShipProperty m_property = new ShipProperty();
                    if (m_isFirstID)
                    {
                        m_property.Id1 = uint.Parse(dateList[i]);
                        m_property.Id2 = uint.Parse(dateList[i]) + 1;
                        m_property.FirstPosition = m_shipWorldPosition;
                    }
                    else
                    {
                        m_property.Id1 = uint.Parse(dateList[i]) - 1;
                        m_property.Id2 = uint.Parse(dateList[i]);
                        m_property.SecondPosition = m_shipWorldPosition;
                    }
                   // m_property.FirstPosition = m_shipWorldPosition;
                    //m_property.SecondPosition = m_shipWorldPosition;
                    m_property.Id = m_shipID;

                    switch (dateList[0])
                    {
                        case "FourID":
                            m_property.Type = ShipProperty.ShipsType.ship_Four;
                            break;
                        case "FiveID":
                            m_property.Type = ShipProperty.ShipsType.ship_Five;
                            break;
                        case "NineID":
                            m_property.Type = ShipProperty.ShipsType.ship_Nine;
                            break;
                        case "TenID":
                            m_property.Type = ShipProperty.ShipsType.ship_Ten;
                            break;
                    }
                    ShipsDictionary.Instance.AddShipDicValues(m_shipID, m_property);
                }
            }
        }
    }
}